package com.atguigu.crowd.handler;

import com.atguigu.crowd.api.MySQLRemoteService;
import com.atguigu.crowd.constant.CrowdConstant;
import com.atguigu.crowd.entity.vo.PortalTypeVO;
import com.atguigu.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author zwj
 * @create 2021-08-05-15:14
 */
@Controller
public class Portalhandler {
    @Autowired
    private MySQLRemoteService mySQLRemoteService;

    @RequestMapping("/")
    public String showPortalPage(ModelMap modelMap){
        // 这里实际开发中需要加载数据……
        //拿到显示数据

        ResultEntity<List<PortalTypeVO>> resultEntity = mySQLRemoteService.getPortalTypeProjectRemote();
        String result = resultEntity.getResult();
        if (ResultEntity.SUCCESS.equals(result)){
            List<PortalTypeVO> portalTypeVOList = resultEntity.getData();
            // 4.存入模型
            modelMap.addAttribute(CrowdConstant.ATTR_NAME_PORTAL_DATA, portalTypeVOList);
        }
        return "portal";
    }
}
